package com.mach.platform.domain.base;

import cn.afterturn.easypoi.excel.annotation.Excel;
import cn.afterturn.easypoi.excel.annotation.ExcelTarget;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import io.swagger.annotations.ApiModel;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicUpdate;

import javax.persistence.*;
import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

/**
 * @author Anonymous
 * @Description: 这里的lombok不用 @Data  注解，，会hashcode报错。暂未知原因
 * @Package: com.mach.platform.practice.com.mach.platform.domain
 * @Time create on 2017/11/10 20:41
 */
@ApiModel(value = "用户表字段")
@Setter
@Getter
@Entity
@JsonIgnoreProperties(value = { "hibernateLazyInitializer", "handler" })
@ExcelTarget("account")
@Table(name = "account")
@DynamicUpdate
public class Account implements Serializable {

	private static final long serialVersionUID = 5274272280448359812L;


	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Long id;

	@Excel(name = "姓名",width = 20)
	private String  name;
	@Excel(name = "登录名",width = 20,orderNum = "1")
	private String  username;
	@Excel(name = "手机号码",width = 30,orderNum = "2")
	private String  mobile;
	@Excel(name = "邮箱",width = 30,orderNum = "3")
	private String  email;
	@Excel(name = "身份证",width = 40,orderNum = "4")
	private String  identity;
	@Excel(name = "出生日期",width = 30,orderNum = "4")
	private String  birthday;
	@Excel(name = "年龄",width = 10,orderNum = "5")
	private Integer age;
	@Excel(name = "性别",width = 10,orderNum = "6", replace = { "女_0", "男_1" })
	private Integer gender;
	@Excel(name = "地址",width = 50,orderNum = "7")
	private String  address;

	@JsonIgnore
	@Column(updatable = false)
	private String  password;

	/**
	 * 是否禁用   0 (禁用) 1 (正常)
	 */
	@Column(columnDefinition = "bit(1) default 1")
	private boolean enabled;

	/**
	 * 岗位Id
	 */
	private Long postId;
	/**
	 * 岗位名称
	 */
	private String postName;
	/**
	 * 组织id
	 */
	private Long orgId;
	/**
	 * 组织名称
	 */
	private String orgName;

	@Transient
	private Set<Role> roles = new HashSet<>();

	@Override
	public String toString ( ) {
		return "Account{" + "id=" + id + ", name='" + name + '\'' + ", username='" + username + '\'' + ", mobile='"
				       + mobile + '\'' + ", email='" + email + '\'' + ", identity='" + identity + '\'' + ", birthday='"
				       + birthday + '\'' + ", age=" + age + ", gender=" + gender + ", address='" + address + '\''
				       + ", password='" + password + '\'' + ", enabled=" + enabled + ", postId=" + postId
				       + ", postName='" + postName + '\'' + ", orgId=" + orgId + ", orgName='" + orgName + '\''
				       + ", roles=" + roles + '}';
	}


}
